<?php
/**
 * Created by PhpStorm.
 * User: dingjinlai
 * Date: 2018/11/16
 * Time: 下午3:53
 */

class Purchase_storage_list_model extends CI_Model
{
    public function storage_list($supp_id = 0)
    {
        $query = $this->db->from('purchase_storage_list as psl')
            ->select('psl.*,s.suppliers_name')
            ->join('suppliers s', 'psl.supp_id = s.suppliers_id', 'left')
            ->where('psl.supp_id', $supp_id)->get();
        
        $_list = $query->result_array();
        
        $list = array();
        
        foreach ($_list as $row) {
            $query1 = $this->db->from('purchase_goods')->select_sum('inv_number')->select_sum('pg_number')->where_in('po_id', explode(',', $row['po_ids']))->where("add_time >= 1550155915")->get();
            $c_num = $query1->row_array();
            
            $row['pg_number'] = $c_num['pg_number'];
            $row['inv_number'] = $c_num['inv_number'];
    
            $list[$row['psl_id']] = $row;
        }
        
        return $list;
    }
    
    public function storage_list_info($psl_id)
    {
        $query = $this->db->from('purchase_storage_list')->where('psl_id', $psl_id)->get();
        
        $info = $query->row_array();
        
        return $info;
    }
}